
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>

int GetEnd(int* a, int n, int m)
{
    int k = 1, j = 0, size = n;

    while (size > 1)
    {
        if (k > m)
        {
            k = 1;
        }
        if (j >= n)
        {
            j = 0;
        }

        while (a[j] == 0)
        {
            j ++ ;
            
            if (j >= n)
            {
                j = 0;
            }
        }

        if (k == m)
        {
            a[j] = 0;
            size -- ;
        }

        k ++ ;
        j ++ ;
    }

    for (int i = 0; i < n; i ++ )
    {
        if (a[i])
        {
            return a[i];
        }
    }

    return 0;
}

int main()
{
    int n, m;
    scanf("%d %d", &n, &m);

    int* tmp = (int*)malloc(sizeof(int) * n);
    assert(tmp);

    for (int i = 0; i < n; i ++ )
    {
        tmp[i] = i + 1;
    }

    printf("%d\n", GetEnd(tmp, n, m));

    free(tmp);

    return 0;
}
